import subprocess
import os
import re


 
def run_inference(file_path, output_dir = 'G:/test_data/output'):
  cmd_base = 'G:/test_data/bin_im2txt/run_inference.exe --checkpoint_path="G:/test_data/flickr8_v3_findtune_model/train" --vocab_file="G:/csdn_ai_homework/end/data/flickr8/flickr8_8/word_counts.txt"'

  cmd_str = ('%s --input_files=%s --output_dir=%s')%(cmd_base,file_path,output_dir)
  process1 = subprocess.Popen(cmd_str, shell=False, stdout = subprocess.PIPE, stderr=subprocess.STDOUT) 

  is_match = 0
  match_str = []    
  while True:
    line = process1.stdout.readline()  
    if not line:  
      break

    if is_match == 1:
      match_str.append(line.decode().strip('\r\n'))
    elif line.decode().find('Captions for image') > -1:
      is_match = 1
      match_str.append(line.decode().strip('\r\n'))

  return match_str